package com.winhxd.b2c.common.feign.customer;

import com.winhxd.b2c.common.constant.BusinessCode;
import com.winhxd.b2c.common.constant.ServiceName;
import com.winhxd.b2c.common.domain.ResponseResult;
import com.winhxd.b2c.common.domain.customer.condition.ShoppingMallRuleCondition;
import com.winhxd.b2c.common.domain.customer.vo.ShoppingMallRuleVO;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author lishaoping
 * @Description: 商城营业设置
 * @date 2019年1月7日15:13:46
 */
@FeignClient(value = ServiceName.CUSTOMER_SERVICE, fallbackFactory = ShoppingMallRuleServiceClientFallBack.class)
public interface ShoppingMallRuleServiceClient {

    /**
     * 保存/修改商城营业设置信息
     */

    @RequestMapping(value = "/customer/2200/v1/saveShoppingMallRule", method = RequestMethod.POST)
    ResponseResult<Boolean> saveShoppingMallRule(@RequestBody ShoppingMallRuleCondition condition);

    /**
     * 查看商城营业设置信息
     */
    @RequestMapping(value = "/customer/2201/v1/findShoppingMallRule", method = RequestMethod.POST)
    ResponseResult<ShoppingMallRuleVO> findShoppingMallRule(@RequestBody ShoppingMallRuleCondition condition);
}

@Component
class ShoppingMallRuleServiceClientFallBack implements ShoppingMallRuleServiceClient, FallbackFactory<ShoppingMallRuleServiceClient> {
    Logger logger = LoggerFactory.getLogger(ShoppingMallRuleServiceClientFallBack.class);
    Throwable throwable;

    @Override
    public ShoppingMallRuleServiceClient create(Throwable throwable) {
        this.throwable = throwable;
        return new ShoppingMallRuleServiceClientFallBack();
    }

    @Override
    public ResponseResult<Boolean> saveShoppingMallRule(ShoppingMallRuleCondition condition) {
        logger.error("ShoppingMallRuleServiceClientFallBack -> saveShoppingMallRule{}", throwable.getMessage());
        return new ResponseResult<Boolean>(BusinessCode.CODE_1001);
    }

    @Override
    public ResponseResult<ShoppingMallRuleVO> findShoppingMallRule(ShoppingMallRuleCondition condition) {
        logger.error("ShoppingMallRuleServiceClientFallBack -> findShoppingMallRule{}", throwable.getMessage());
        return new ResponseResult<ShoppingMallRuleVO>(BusinessCode.CODE_1001);
    }
}
